package com.sike.javacore.serializer.serializable;

import com.sike.javacore.serializer.serializable.dto.UserInfo;

import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;

public class Serializable04 {

    public static void main(String[] args) throws Exception {
        UserInfo userInfo = new UserInfo(1001L,"zhangshan","张三");

        // 序列化
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ObjectOutputStream out = new ObjectOutputStream(bout);
        out.writeObject(userInfo);
        out.flush();
        out.close();
        System.out.println("原生 JDK 序列化生成的字节流大小：" + bout.toByteArray().length);
        bout.close();

        // 原生字节码
        System.out.println("UserInfo 对象字节流大小：" + userInfo.codeC().length);
    }
}
